#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e3+10;
const int MAXS = 1e6+10;

int barrel[MAXS]; int a[MAXN]; int l[MAXN];
int color[MAXN]; int ans = 0; int n; 

void dfs(int depth){
    if(depth > n){
        int lst_r=0,lst_b=0; int cnt = 0;
        for(int i=1;i<=n;i++){
            if(color[i] == 1){
                if(a[lst_r] == a[i]){cnt += a[i]; }
                lst_r = i;
            } else {
                if(a[lst_b] == a[i]){cnt += a[i]; }
                lst_b = i;
            }
        }
        ans = max(cnt,ans);
        return;
    }
    for(int i=0;i<=1;i++){
        color[depth] = i;
        dfs(depth+1);
    }
}

void solve(){
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    ans = 0;
    dfs(0);
    cout << ans << '\n';
    return;
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t; cin >> t;
    while(t--){
        solve();
    }
    return 0;
}